package com.example.admin.controller;


import com.example.admin.common.Result;
import com.example.admin.entity.ActivityRecord;
import com.example.admin.service.ActivityRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8080")
public class ActivityRecordController {

    @Autowired
    private ActivityRecordService activityRecordService;


    @GetMapping("/selectActivityRecordPage")
    public Result<PageInfo> selectActivityRecordPage(@RequestParam Integer pageNumber,@RequestParam Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
       List<ActivityRecord> activityRecordList= activityRecordService.selectActivityRecordPage();
       PageInfo<ActivityRecord> pageInfo=new PageInfo<>(activityRecordList);
       return Result.success(pageInfo);


    }

    @PostMapping("/addActivityRecord")
    public Result addActivityRecord(@RequestBody ActivityRecord activityRecord) {

     Result result=   activityRecordService.addActivityRecord(activityRecord);
     return result;
    }

    @PutMapping("/editeActivityRecord")
    public Result editActivityRecord(@RequestBody ActivityRecord activityRecord) {
      Result result=  activityRecordService.editActivityRecord(activityRecord);
      return result;
    }

    @DeleteMapping("/deleteActivityRecordById/{id}")
    public Result deleteActivityRecordById(@PathVariable Integer id) {
       Result result= activityRecordService.deleteActivityRecordById(id);
       return result;
    }

    @GetMapping("/selectActivityRecordById")
    public Result<PageInfo> selectActivityRecordById(@RequestParam Integer elderId) {

        PageHelper.startPage(1,1);
       List<ActivityRecord> activityRecordList= activityRecordService.selectActivityRecordById(elderId);
       PageInfo<ActivityRecord> pageInfo=new PageInfo<>(activityRecordList);
       return Result.success(pageInfo);
    }
}
